home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / MUI / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  3.9 KB  |  206 lines

  1. #include "defs.h"
  2.  
  3. char AppWindow [] = "CON:0/0/640/200/VMM Window/CLOSE/AUTO/WAIT";
  4. static UBYTE **ToolTypes;
  5.  
  6. static BOOL OpenLibs1 (void)
  7.  
  8. {
  9. if ((IconBase = OpenLibrary ("icon.library", 0L)) == NULL)
  10.   {
  11.   printf ("Couldn't open icon.library\n");
  12.   return (FALSE);
  13.   }
  14.  
  15. if ((CxBase = OpenLibrary ("commodities.library", 0L)) == NULL)
  16.   {
  17.   printf ("Couldn't open commodities.library\n");
  18.   return (FALSE);
  19.   }
  20.  
  21. if ((UtilityBase = OpenLibrary ("utility.library", 37L)) == NULL)
  22.   {
  23.   printf ("Couldn't open utility.library\n");
  24.   return (FALSE);
  25.   }
  26.  
  27. return (TRUE);
  28. }
  29.  
  30. /**********************************************************************/
  31.  
  32. static BOOL OpenLibs2 (void)
  33.  
  34. {
  35. if ((AslBase = OpenLibrary ("asl.library", 37L)) == NULL)
  36.   {
  37.   printf ("Couldn't open asl.library\n");
  38.   return (FALSE);
  39.   }
  40.  
  41. if ((IntuitionBase = OpenLibrary ("intuition.library", 37L)) == NULL)
  42.   {
  43.   printf ("Couldn't open intuition.library\n");
  44.   return (FALSE);
  45.   }
  46.  
  47. if ((MUIMasterBase = OpenLibrary (MUIMASTER_NAME, 10L)) == NULL)
  48.   {
  49.   printf ("Couldn't open muimaster.library V10\n"
  50.           "You need at least MUI 2.3 to run VMM\n");
  51.   return (FALSE);
  52.   }
  53.  
  54. LocaleBase = OpenLibrary ("locale.library", 38L);
  55.  
  56. OpenVMMCatalog (NULL, NULL);
  57.  
  58. return (TRUE);
  59. }
  60.  
  61. /**********************************************************************/
  62.  
  63. static void CloseAll (void)
  64.  
  65. {
  66. if (ExtCxPort != NULL)
  67.   {
  68.   ExtCxPort->PrefsTask = NULL;
  69.   if (ExtCxPort->ShowSignal != -1L)
  70.     FreeSignal (ExtCxPort->ShowSignal);
  71.   ExtCxPort->ShowSignal = -1;
  72.   }
  73.  
  74. UninstallAsCommodity ();      /* only does it, if CxParams haven't been
  75.                                * sent to VMM. */
  76. if (ToolTypes != NULL)
  77.   ArgArrayDone ();
  78.  
  79. CloseVMMCatalog ();
  80.  
  81. if (LocaleBase != NULL)
  82.   CloseLibrary (LocaleBase);
  83. if (MUIMasterBase != NULL)
  84.   CloseLibrary (MUIMasterBase);
  85. if (IntuitionBase != NULL)
  86.   CloseLibrary (IntuitionBase);
  87. if (AslBase != NULL)
  88.   CloseLibrary (AslBase);
  89. if (UtilityBase != NULL)
  90.   CloseLibrary (UtilityBase);
  91. if (IconBase != NULL)
  92.   CloseLibrary (IconBase);
  93. if (CxBase != NULL)
  94.   CloseLibrary (CxBase);
  95. }
  96.  
  97. /**********************************************************************/
  98.  
  99. int main (LONG argc, UBYTE **argv)
  100.  
  101. {
  102. BOOL Quit;
  103. BOOL QuestionMark;
  104.  
  105. if (!OpenLibs1 ())
  106.   {
  107.   CloseAll ();
  108.   return (10);
  109.   }
  110.  
  111. ToolTypes = ArgArrayInit (argc, argv);
  112.  
  113. if (ToolTypes == NULL)
  114.   {
  115.   ForceOverwrite = FALSE;
  116.   ShowGUI = TRUE;
  117.   CXPri = 0L;
  118.   CXPopKey = DEFAULT_POPKEY;
  119.   Quit = FALSE;
  120.   QuestionMark = FALSE;
  121.   CfgName = CFG_NAME_USE;
  122.   }
  123. else
  124.   {
  125.   ShowGUI = (Stricmp (ArgString (ToolTypes, "CX_POPUP", "YES"), "YES") == 0);
  126.   CXPri = ArgInt (ToolTypes, "CX_PRIORITY", 0L);
  127.   CXPopKey = ArgString (ToolTypes, "CX_POPKEY", DEFAULT_POPKEY);
  128.   Quit = (FindToolType (ToolTypes, "QUIT") != NULL);
  129.   QuestionMark = (FindToolType (ToolTypes, "?") != NULL);
  130.   CfgName = ArgString (ToolTypes, "SETTINGS", CFG_NAME_USE);
  131.   ForceOverwrite = (FindToolType (ToolTypes, "FORCE") != NULL);
  132.   }
  133.  
  134. if (QuestionMark)
  135.   {
  136.   printf ("CX_PRIORITY/K/N,CX_POPKEY/K,CX_POPUP/K,SETTINGS/K,QUIT/S,FORCE/S\n");
  137.   CloseAll ();
  138.   return (0);
  139.   }
  140.           
  141. if (Quit)
  142.   {
  143.   if (!StopVMM ())
  144.     printf ("VMM is not running\n");
  145.  
  146.   CloseAll ();
  147.   return (0);
  148.   }
  149.  
  150. ExtCxPort = (struct ExtPort*) FindPort (CXPORTNAME);
  151.  
  152. if (ExtCxPort == NULL)
  153.   {
  154.   ReadHotkeysFromConfig (CfgName);
  155.  
  156.   /* This sets ExtCxPort */
  157.   if (!InstallAsCommodity ())
  158.     {
  159.     printf ("Couldn't install commodity\n");
  160.     CloseAll ();
  161.     return (10);
  162.     }
  163.   }
  164.  
  165. ExtCxPort->PrefsTask = FindTask (NULL);
  166. ExtCxPort->ShowSignal = AllocSignal (-1L);
  167.  
  168. if (ShowGUI || VMM_RUNNING)
  169.   {
  170.   if (!OpenLibs2 ())
  171.     {
  172.     CloseAll ();
  173.     return (10);
  174.     }
  175.  
  176.   if (HandleGUI () == Q_QUITBOTH)
  177.     {
  178.     Forbid ();
  179.     CloseLibrary (MUIMasterBase);
  180.     RemLibrary (MUIMasterBase);
  181.     Permit ();
  182.     MUIMasterBase = NULL;
  183.     StopVMM ();
  184.     }
  185.   }
  186. else
  187.   {
  188.   /* Simply start up VMM */
  189.   ReadHotkeysFromConfig (CfgName);
  190.  
  191.   StartVMM ();
  192.   }
  193.  
  194. CloseAll ();
  195. }
  196.  
  197. #ifdef __GNUC__
  198.  
  199. /* Just a dummy needed by GCC */
  200. void __main (void)
  201.  
  202. {
  203. }
  204.  
  205. #endif
  206.